using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Warehouse;
using HengTong.Model;


namespace HengTong.ViewModel.SupplyChain.SysWarehouseLocationVms
{
    public partial class SysWarehouseLocationListVm : BaseListVm<SysWarehouseLocationView, SysWarehouseLocationSearcher>
    {

        protected override IEnumerable<IGridColumn<SysWarehouseLocationView>> InitGridHeader()
        {
            return new List<GridColumn<SysWarehouseLocationView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.ErpId),
                this.MakeGridHeader(x => x.AreaName),
                this.MakeGridHeader(x => x.WarehouseName),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.CommonState),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysWarehouseLocationView> GetSearchQuery()
        {
            var query = DC.Set<SysWarehouseLocation>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.ErpId, x=>x.ErpId)
                .CheckEqual(Searcher.AreaId, x=>x.AreaId)
                .CheckEqual(Searcher.WarehouseId, x=>x.WarehouseId)
                .CheckEqual(Searcher.CommonState, x=>x.CommonState)
                .Select(x => new SysWarehouseLocationView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    ErpId = x.ErpId,
                    AreaName = x.Area.Name,
                    WarehouseName = x.Warehouse.Name,
                    Description = x.Description,
                    CommonState = x.CommonState,
                })
                .OrderBy(x => x.Code);
            return query;
        }
    }

    public class SysWarehouseLocationView : SysWarehouseLocation{
        [Display(Name = "库区名称")]
        public String AreaName { get; set; }
        [Display(Name = "仓库名称")]
        public String WarehouseName { get; set; }

    }
}
